{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Order deep-review authors\n",
    "Create multiple types of equal contributions.  Within a [contribution class](https://github.com/greenelab/deep-review/pull/508#issue-231012181), authors are randomly ordered.  Once an initial ordering has been made, any new authors (for example, authors added during revisions) are placed at the end of the ordered list for the appropriate contribution class in a random order.  A [pre-registered seed](https://github.com/greenelab/deep-review/issues/369#issuecomment-302125051) makes the ordering deterministic."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Function to print the ordered contribution classes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "def print_authors(contrib_map):\n",
    "    authors = []\n",
    "    for contrib_type in sorted(contrib_map.keys()):\n",
    "        authors.extend(contrib_map[contrib_type])\n",
    "    print('{}\\n'.format(', '.join(authors)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Order and print the contribution classes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Before ordering\n",
      "@agapow, @alxndrkalinin, @bdo311, @brettbj, @dhimmel, @enricoferrero, @gwaygenomics, @traversc, @AnneCarpenter, @AvantiShri, @blengerich, @evancofer, @gailrosen, @j3xugit, @jacklanchantin, @jisraeli, @sw1, @XieConnect, @akundaje, @DaveDeCaprio, @davharris, @laurakwiley, @mrwns, @qiyanjun, @yfpeng, @agitter, @cgreene\n",
      "\n",
      "After initial ordering\n",
      "@traversc, @dhimmel, @brettbj, @alxndrkalinin, @bdo311, @gwaygenomics, @enricoferrero, @agapow, @XieConnect, @gailrosen, @blengerich, @jisraeli, @jacklanchantin, @sw1, @AnneCarpenter, @AvantiShri, @j3xugit, @evancofer, @davharris, @DaveDeCaprio, @qiyanjun, @akundaje, @yfpeng, @laurakwiley, @mrwns, @agitter, @cgreene\n",
      "\n",
      "After adding authors\n",
      "@traversc, @dhimmel, @brettbj, @alxndrkalinin, @bdo311, @gwaygenomics, @enricoferrero, @agapow, @zietzm, @michaelmhoffman, @XieConnect, @gailrosen, @blengerich, @jisraeli, @jacklanchantin, @sw1, @AnneCarpenter, @AvantiShri, @j3xugit, @evancofer, @lavenderca, @SriniTuraga, @alexandari, @luzh2, @davharris, @DaveDeCaprio, @qiyanjun, @akundaje, @yfpeng, @laurakwiley, @mrwns, @SiminaB, @swamidass, @austinvhuang, @agitter, @cgreene\n",
      "\n",
      "27 original authors\n",
      "9 new authors\n",
      "36 total authors\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "from collections import defaultdict\n",
    "from functools import reduce\n",
    "\n",
    "# see above for how the seed was determined in advance\n",
    "random.seed(0x06edef4bee392038b3e0403b0fa4208e11ddcc5d)\n",
    "\n",
    "# map contribution types to lists of original authors\n",
    "contrib_map = dict()\n",
    "# lead contribution\n",
    "contrib_map['01_lead'] =\\\n",
    "    ['@agapow', '@alxndrkalinin', '@bdo311', '@brettbj', '@dhimmel', '@enricoferrero', '@gwaygenomics', '@traversc']\n",
    "# default contribution\n",
    "contrib_map['02_default'] =\\\n",
    "    ['@AnneCarpenter', '@AvantiShri', '@blengerich', '@evancofer', '@gailrosen', '@j3xugit', '@jacklanchantin', '@jisraeli', '@sw1', '@XieConnect']\n",
    "# other contribution\n",
    "contrib_map['03_other'] =\\\n",
    "    ['@akundaje', '@DaveDeCaprio', '@davharris', '@laurakwiley', '@mrwns', '@qiyanjun', '@yfpeng']\n",
    "# corresponding authors\n",
    "contrib_map['04_corresponding'] = ['@agitter', '@cgreene']\n",
    "\n",
    "original_count = reduce((lambda x,y: x+y), map(len, contrib_map.values()))\n",
    "\n",
    "print('Before ordering')\n",
    "print_authors(contrib_map)\n",
    "\n",
    "contrib_types = sorted(contrib_map.keys())\n",
    "\n",
    "# order all initial authors\n",
    "for contrib_type in contrib_types:\n",
    "    random.shuffle(contrib_map[contrib_type])\n",
    "\n",
    "print('After initial ordering')\n",
    "print_authors(contrib_map)\n",
    "\n",
    "# new authors after revisions\n",
    "new_contrib_map = defaultdict(list)\n",
    "# lead contribution\n",
    "new_contrib_map['01_lead'] = ['@michaelmhoffman', '@zietzm']\n",
    "# default contribution\n",
    "new_contrib_map['02_default'] = ['@alexandari', '@lavenderca', '@luzh2', '@SriniTuraga']\n",
    "# other contribution\n",
    "new_contrib_map['03_other'] = ['@austinvhuang', '@SiminaB', '@swamidass']\n",
    "\n",
    "new_count = reduce((lambda x,y: x+y), map(len, new_contrib_map.values()))\n",
    "\n",
    "# add new authors to the end of the existing category in a random order\n",
    "for contrib_type in contrib_types:\n",
    "    random.shuffle(new_contrib_map[contrib_type])\n",
    "    contrib_map[contrib_type].extend(new_contrib_map[contrib_type])\n",
    "\n",
    "print('After adding authors')\n",
    "print_authors(contrib_map)\n",
    "\n",
    "# total number of authors\n",
    "print('{} original authors'.format(original_count))\n",
    "print('{} new authors'.format(new_count))\n",
    "print('{} total authors'.format(original_count + new_count))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
